package com.ctbri.concurrency;

import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class Ex6 implements Runnable{

	private static Random random = new Random();
	private final int id;
	public Ex6(int id) {
		this.id = id;
	}
	public void run() {
		int milliSeconds = random.nextInt(10) + 1;
		try {
			TimeUnit.MILLISECONDS.sleep(milliSeconds);
		} catch (InterruptedException e) {
			System.out.println("Interrupted");
		}
		System.out.println("The thread {" + id + "} has sleeped " + milliSeconds + "!");
	}
	public static void main(String[] args) {
		ExecutorService exec = Executors.newCachedThreadPool();
		for(int i = 0; i < 20; i++)
			exec.execute(new Ex6(i));
		exec.shutdown();
	}

}
